home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Floppyshop 2
/
Floppyshop - 2.zip
/
Floppyshop - 2.iso
/
art&graf.ix
/
art-0039
/
generatr
/
save.c
< prev
Wrap
C/C++ Source or Header
|
1997-04-16
|
19KB
|
696 lines
#include <bitmap.h>
#include <extdefs.h>
#include <osbind.h>
#include <stdio.h>
#include <gemdefs.h>
/* Input a string */
get_string(saying,address,max,ding)
char *saying, *address;
int max, ding;
{
char *pointer, str[3];
int width, length, i, j, k, count, kp, array[10], rbox[4], x, y;
HIDE_MOUSE;
sscreen( SAVE );
pointer = address;
k = count = kp = 0;
display_image_names();
if( !names ) k = 30;
/* Figure out the width according to which is longer, the
destination string or the box title */
length = strlen(saying);
if( length > max ) width = length;
else width = max;
/* Assign the parameters to draw a box */
/* First the x coordinates */
if( !rez ) array[0] = k + 130 - width * 4 - 16, array[2] = k + 130 + width * 4 + 16;
else array[0] = 320 - width * 4 - 16, array[2] = 320 + width * 4 + 16;
array[6] = array[8] = array[0];
array[4] = array[2];
/* Then the y coordinates */
if( rez < 2 ) array[1] = 70, array[5] = 130;
else array[1] = 140, array[5] = 260;
array[3] = array[9] = array[1];
array[7] = array[5];
/* Coordinates for the filled rectangle */
rbox[0] = array[0];
rbox[1] = array[1];
rbox[2] = array[2];
rbox[3] = array[5];
/* Set the writing mode */
vswr_mode( handle, 1 );
/* Set fill attributes */
vsf_interior( handle, 1 );
vsf_style( handle, 8 );
vsf_color( handle, 0 );
/* Set the line color */
vsl_color( handle, 1 );
/* Make a box */
v_pline( handle, 5, array );
vr_recfl( handle, rbox );
/* Now make it have a double lined border */
array[0] += 2;
array[2] -= 2;
array[1] += 2;
array[5] -= 2;
array[6] = array[8] = array[0];
array[4] = array[2];
array[3] = array[9] = array[1];
array[7] = array[5];
v_pline( handle, 5, array );
/* Put the title on the box */
i = strlen(saying);
if( !rez ) i = k + 130 - i * 4;
else i = 320 - i * 4;
y = array[1] + 20;
if( rez == 2 ) y += 8;
v_gtext( handle, i, y, saying );
/* Put the underscores in place */
vst_color( handle, 1 );
if( rez == 0 )x = k + 130 - max * 4;
else x = 320 - max * 4;
if( rez != 2 ) y = array[1] + 40;
else y = array[1] + 80;
for( i=0; i<max; i++ ) v_gtext( handle, x + i * 8, y, "_" );
while( kp != 13 ){
/* Get a keypress */
kp = Crawcin();
/* Was it a backspace? */
if( count && kp == 8 ){
v_gtext( handle, x + count * 8 - 8, y, "_" );
pointer--;
count--;
}
/* Was it a valid digit? */
if( kp > 31 && kp < 123 ){
if( count < max ){
str[0] = (char)kp;
str[1] = 0;
count++;
v_gtext( handle, x + count * 8 - 8, y, str );
*pointer++ = str[0];
}else{
if( ding ) Bconout( 2,7 );
}
}
/* Was it ESCAPE? */
if( kp == 27 ){
count = 0;
pointer = address;
for( i=0; i<max; i++ ) v_gtext( handle, x + i * 8, y, "_" );
}
}/* End while( kp != 27 ) */
/* Null terminate the string */
*pointer = 0;
names++;
pointer = address;
j = 0;
for( i=0; i<10; i++ ){
if( *pointer == 0 ) j = 1;
if( !j ) image_names[(names-1)*10+i] = *pointer++;
else image_names[(names-1)*10+i] = 32;
}
sscreen( RESTORE );
SHOW_MOUSE;
}/* End get_string() function */
display_image_names()
{
int array[10], rbox[4], i, j, k;
char junk[20];
if( names ){
/* Assign the parameters to draw a box */
/* First the x coordinates */
if( !rez ) array[0] = 217, array[2] = 319;
else array[0] = 400, array[2] = 639;
array[6] = array[8] = array[0];
array[4] = array[2];
/* Then the y coordinates */
if( rez < 2 ) array[1] = 0, array[5] = 199;
else array[1] = 0, array[5] = 399;
array[3] = array[9] = array[1];
array[7] = array[5];
/* Coordinates for the filled rectangle */
rbox[0] = array[0];
rbox[1] = array[1];
rbox[2] = array[2];
rbox[3] = array[5];
/* Set the writing mode */
vswr_mode( handle, 1 );
/* Set fill attributes */
vsf_interior( handle, 1 );
vsf_style( handle, 8 );
vsf_color( handle, 0 );
/* Set the line color */
vsl_color( handle, 1 );
/* Make a box */
v_pline( handle, 5, array );
vr_recfl( handle, rbox );
/* Now make it have a double lined border */
array[0] += 2;
array[2] -= 2;
array[1] += 2;
array[5] -= 2;
array[6] = array[8] = array[0];
array[4] = array[2];
array[3] = array[9] = array[1];
array[7] = array[5];
v_pline( handle, 5, array );
if( rez != 2 ) v_gtext( handle, array[0]+5+rez*20, 11, "Image Names" );
else v_gtext( handle, array[0]+25, 22, "Image Names" );
rbox[0] += 3;;
rbox[2] -= 3;
rbox[1] += 14;
rbox[3] -= 3;
k = 0;
for( i=0; i<names; i++ ){
for( j=0; j<10; j++ ) junk[j] = image_names[i*10+j];
junk[10] = 0;
if( rez != 2 ) v_gtext( handle, array[0]+5+rez*20, array[1] + 21 + k * 8, junk );
else v_gtext( handle, array[0]+25, array[1] + 42 + k * 16, junk );
if( i && !( i % 19 ) && i != names - 1 ){
if( rez != 2 ) v_gtext( handle, array[0]+5+rez*16, 191, "Press key" );
else v_gtext( handle, array[0]+25, 382, "Press key" );
j = Crawcin();
k = 0;
if( j != 27 ) vr_recfl( handle, rbox );
else i = 1000;
}else{
k++;
}
}
}
}
/* Process the rectangle and then save it */
image(address,format)
long address;
int format;
{
char junk[40],array[40],temp[200];
int *holder, *data;
int fd = -1;
unsigned int append, i, j, k, numwords, counter, iterations, nplanes, width, height, wordwidth, maskflag, device, blit[8];
long err, fsize, *blank;
FDB source, dest;
long int output();
/* See if they want to save the mask also */
maskflag = form_alert( 1,"[2][| Save Bit Image Mask? |][Yes|No|Cancel]" );
do{ GET_MOUSE; } while( button );
if( maskflag == 3 ) return( 0 );
maskflag = 2 - maskflag;
if( maskflag >= 0 ){
/* Get the output device (or cancel) */
device = form_alert( 1, "[2][| Output Device? |][Disk|Printer|Cancel]" );
do{ GET_MOUSE; } while( button );
}else{
device = 5;
}
/* If printer is target device, check its readiness */
if( device == 2 ){
while( !Cprnos() && device < 3 ){
i = form_alert( 1,"[1][|Prepare Printer for Output|][Ok|Cancel]" );
do{ GET_MOUSE; } while( button );
if( i == 2 ) device = 3;
}
}
/* If 'cancel' was not selected from output device selection...*/
if( device < 3 ){
/* Clear the destination buffer */
blank = (long *)temp_scrn;
for( i=0; i<8000; i++ ) *blank++ = 0L;
/* Have them enter the array name */
if( format != TO_DATA ) get_string( "Enter Array Name", array, 10, 1 );
/* If the output device is a disk, get the filename */
if( device == 1 ){
/* Set the extender */
switch( format ){
case TO_C: strcpy( junk, "C" ); break;
case TO_ASM: strcpy( junk, "S" ); break;
case TO_GFA: strcpy( junk, "LST" ); break;
case TO_DATA: strcpy( junk, "DAT" ); break;
}
/* Get file name */
HIDE_MOUSE;
sscreen( SAVE );
SHOW_MOUSE;
i = get_filename( junk );
if( !i ) names--;
do{ GET_MOUSE; } while( button );
HIDE_MOUSE;
sscreen( RESTORE );
SHOW_MOUSE;
if( i ){
/* If file selected, look for it on disk */
/* If it is there, ask if they want to append or overwrite */
j = append = 0;
if( Fsfirst( filename, 0 ) == 0 ){
j = form_alert( 1, "[2][| File Already Exists! |][Replace|Append]" );
do{ GET_MOUSE; } while( button );
if( j == 2 ){
fd = Fopen( filename, 1 );
Fseek( 0L, fd, 2 );
append = 1;
}
}
if( j != 2 ){
fd = Fcreate( filename, 0 );
for( j=0; j<10; j++ ) junk[j] = image_names[(names-1)*10+j];
for( j=0; j<10; j++ ) image_names[j] = junk[j];
names = 1;
}
}/* End if( i ) */
}/* End if( device == 1 ) */
/* Either the output device is the printer or a file was
selected */
if( device == 2 || ( device == 1 && i ) ){
/* Figure width, height, wordwidth, and number of planes */
width = abs( rx1 - rx2 ) + 1;
height = abs( ry1 - ry2 ) + 1;
switch( rez ){
case 0: nplanes = 4; break;
case 1: nplanes = 2; break;
case 2: nplanes = 1; break;
}
wordwidth = width / 16;
if( width % 16 ) wordwidth++;
/* Set the structure address pointers */
dest.fd_addr = temp_scrn;
source.fd_addr = address;
/* Set the source structure for the proper values */
switch( rez ){
case 0: source.fd_w = 320;
source.fd_h = 200;
source.fd_wdwidth = 20;
source.fd_nplanes = 4;
break;
case 1: source.fd_w = 640;
source.fd_h = 200;
source.fd_wdwidth = 40;
source.fd_nplanes = 2;
break;
case 2: source.fd_w = 640;
source.fd_h = 400;
source.fd_wdwidth = 40;
source.fd_nplanes = 1;
break;
}
/* Set the destination structure */
dest.fd_w = wordwidth * 16;
dest.fd_h = height;
dest.fd_nplanes = nplanes;
dest.fd_wdwidth = wordwidth;
/* Misc structure values */
dest.fd_stand = source.fd_stand = 0;
dest.fd_r1 = source.fd_r1 = 0;
dest.fd_r2 = source.fd_r2 = 0;
dest.fd_r3 = source.fd_r3 = 0;
i = maskflag + 1;
while( i ){
i--;
/* How many hex words must be output */
iterations = wordwidth * nplanes * height;
/* Zero the word counter ( 8 are output at a time ) */
numwords = 0;
/* Array names */
switch( format ){
case TO_C: strcpy( temp, "int " );
strcat( temp, array );
if( !i && maskflag ) strcat( temp, "_mask" );
strcat( temp, "[]={\15\12" );
break;
case TO_GFA: if( i || !maskflag )
sprintf( temp, "%s:\15\12DATA &H%04x,&H%04x,&H%04x,", array, (wordwidth*16)-1, height-1,nplanes );
else sprintf( temp, "%s_mask:\15\12DATA &H%04x,&H%04x,&H%04x,", array, (wordwidth*16)-1, height-1,nplanes );
numwords = 3;
break;
case TO_ASM: strcpy( temp, array );
if( !i && maskflag ) strcat( temp, "_mask" );
strcat( temp, ":\15\12" );
break;
}
err = 0L;
/* Output the initial string */
if( format == TO_ASM || format == TO_C ) err = output( temp, device, fd );
/* If no error... */
if( err >= 0L ){
blit[0] = rx1; blit[1] = ry1;
blit[2] = rx2; blit[3] = ry2;
blit[4] = blit[5] = 0;
blit[6] = width - 1;
blit[7] = height - 1;
vro_cpyfm( handle, 3, blit, &source, &dest );
data = (int *)dest.fd_addr;
if( format != TO_DATA ){
for( counter=0; counter<iterations; counter++ ){
/* Start a new line of text */
if( !numwords ){
switch( format ){
case TO_C: strcpy( temp, "" ); break;
case TO_ASM: strcpy( temp, "\11\11.dc.w " ); break;
case TO_GFA: strcpy( temp, "DATA " ); break;
}
}
/* Convert the data to ASCII format */
if( format == TO_GFA ) strcat( temp, "&H" );
else if( format == TO_ASM ) strcat( temp, "$" );
else if( format == TO_C ) strcat( temp, "0x" );
if( !i && maskflag ){
if( !(counter % nplanes ) ){
holder = data;
j = 0;
for( k=0; k<nplanes; k++ ) j = j | *holder++;
j ^= 0xffff;
*data = j;
}else{
*data = j;
}
}
/* Do the actual conversion */
sprintf( junk, "%04x", *data++ );
strcat( temp, junk );
numwords++;
/* Allow only eight words across */
if( numwords == 8 ){
if( format == TO_C && counter < iterations - 1 ) strcat( temp, "," );
strcat( temp, "\15\12" );
numwords = 0;
err = output( temp, device, fd );
}else if( counter < iterations - 1 ){
strcat( temp, "," );
}
if( err < 0L ) break;
}/* End counter loop */
if( err >= 0L ){
/* If any words have not been printed...*/
if( numwords ){
temp[strlen(temp)]=0;
strcat( temp, "\15\12" );
output( temp,device,fd );
}
/* Close the string */
if( format == TO_C ){
strcpy( junk, "};\15\12" );
output( junk,device,fd );
}
strcpy( junk, "\15\12" );
output( junk,device, fd );
/* Make the comments (remarks) to indicate
the image size information */
if( !maskflag || !i ){
sprintf( junk, "Width = %d\15\12", wordwidth*16 );
switch( format ){
case TO_C: strcpy( temp, "/*\15\12** " ); break;
case TO_ASM: strcpy( temp, "* " ); break;
case TO_GFA: strcpy( temp, "REM " ); break;
}
strcat( temp, junk );
sprintf( junk, "Height = %d\15\12", height );
switch( format ){
case TO_C: strcat( temp, "** " ); break;
case TO_ASM: strcat( temp, "* " ); break;
case TO_GFA: strcat( temp, "REM " ); break;
}
strcat( temp, junk );
sprintf( junk, "Word Width = %d\15\12", wordwidth );
switch( format ){
case TO_C: strcat( temp, "** " ); break;
case TO_ASM: strcat( temp, "* " ); break;
case TO_GFA: strcat( temp, "REM " ); break;
}
strcat( temp, junk );
sprintf( junk, "Number of planes = %d\15\12", nplanes );
switch( format ){
case TO_C: strcat( temp, "** " ); break;
case TO_ASM: strcat( temp, "* " ); break;
case TO_GFA: strcat( temp, "REM " ); break;
}
strcat( temp, junk );
if( format == TO_GFA ) sprintf( junk, "REM %d data words to read\15\12", wordwidth*nplanes*height+3 ), strcat( temp, junk );
if( format == TO_C ) strcat( temp, "*/\15\12" );
strcat( temp, "\15\12" );
err = output( temp, device, fd );
}
}/* End if( err >= 0L ) */
}else{
/* Save the block of data */
fsize = (long int)iterations;
fsize &= 0x0000ffff;
fsize *= 2L;
if( ( i && maskflag ) || ( !i && !maskflag ) ){
if( append ){
Fseek( 0L, fd, 0 );
Fread( fd, 2L, &append );
append++;
Fseek( 0L, fd, 0 );
Fwrite( fd, 2L, &append );
Fseek( 0L, fd, 2 );
}else{
append = 1;
Fwrite( fd, 2L, &append );
}
}
if( !i && maskflag ){
data = (int *)dest.fd_addr;
holder = data;
while( iterations ){
j = 0;
for( k=0; k<nplanes; k++ ) j = j | *holder++;
j ^= 0xffff;
for( k=0; k<nplanes; k++ ) *data++ = j, iterations--;
}
}
if( ( i && maskflag ) || ( !i && !maskflag ) ){
j = rez + maskflag * 256;
Fwrite( fd, 2L, &j );
j = wordwidth * 16;
Fwrite( fd, 2L, &j );
Fwrite( fd, 2L, &height );
Fwrite( fd, 4L, &fsize );
}
Fwrite( fd, fsize, dest.fd_addr );
}
}/* End if( err >= 0L ) */
if( err < 0L ) form_alert( 1, "[1][| Disk Write Error! |][Ok]" );
do{ GET_MOUSE; } while( button );
}/* End while( i ) */
if( fd >= 0 ) Fclose( fd );
}/* End if( device == 2 || ( device == 1 && i ) ) */
}/* End if( device < 3 ) */
graf_mkstate( &i, &i, &i, &i );
}/* End image() function */
/* Do the actual output */
long output(address,device,fd)
char *address;
int device,fd;
{
unsigned int length;
long err, llength;
length = strlen(address);
llength = (long int)length;
llength &= 0x0000ffff;
if( device == 2 ) while( *address ) Bconout( 0, *address++ );
else err = Fwrite( fd, llength, address );
return( err );
}/* End output() function */
/******************************************************
* get_filename(): *
* This routine displays the file selector and returns *
* a usable filename to the user, it also returns the *
* button which caused the file selector to exit. *
* *
* ext: the extension of the filenames to show *
******************************************************/
get_filename( ext )
char ext[];
{
char *junkp; /* junk pointer */
char tmp_name[14]; /* filename returned by fsel_input() */
char scratch[110]; /* scratch string used to build full pathname */
int exit_button, i, ret; /* miscellaneous variables */
/*
** Initialize the strings to hold the filename returned
** from the file selector and the filename that will be
** returned to the calling routine.
*/
tmp_name[0] = filename[0] = '\0';
/* append the extension to the end of pathname */
Dgetpath(scratch,Dgetdrv());
sprintf( pathname, "%c:%s", Dgetdrv()+'A', scratch );
strcpy( scratch, pathname );
strcat( scratch, "\*." );
strcat( scratch, ext );
/* show the file selector to get the path and file names. */
ret = fsel_input( scratch, tmp_name, &exit_button );
/* return if CANCEL was selected */
if( exit_button == 0 ) return( exit_button );
/* return if the filename is blank */
if( tmp_name[0] == '\0' ) return(0);
/* if the extension isn't "*" then append it to the filename */
ret = strcmp( ext, "*" );
if( ret != 0 )
{
/* try to find a '.' character */
i = strlen( tmp_name );
while( tmp_name[i] != '.' && i >= 0 ) i--;
/* if one was found then make the '.' an end of string char. */
if( tmp_name[i] == '.' ) tmp_name[i] = '\0';
/* concatenate the extension to the end of the filename */
strcat( tmp_name, "." ); strcat( tmp_name, ext );
}
/*
** move backwards through the string and add nulls
** until a '\' or ':' is found. This makes a usable
** pathname without the trailing '*','?', etc.
*/
junkp = strlen( scratch ) + scratch;
for( ; junkp > scratch; junkp-- )
{
if( *junkp == '\\' || *junkp == ':' ) break;
*junkp = '\0';
}
/* copy the truncated pathname back to original string */
strcpy(pathname,scratch);
/*
** combine the fixed path string and the filename
** string into a full, usable pathname.
*/
strcpy( filename, scratch );
strcat( filename, tmp_name );
/* return button selected from file selector */
return( exit_button );
} /* End of get_filename() */